export OUTPUT=new_product
##CC =arm-linux-gcc
CC = gcc
CPLUSPLUS=g++
ifeq ($(RELEASE),1)
	export OUTPUT_DIR=./RELEASE/
	CFLAGS += -O2 -DRELEASE
else
	export OUTPUT_DIR=./DEBUG/
	CFLAGS += -g -O0
endif

ifeq ($(CC),arm-linux-gcc)
CFLAGS +=  -mcpu=arm920t -mtune=arm9tdmi 
else 
CFLAGS +=
endif

INCLUDE_PATHS = -I. -I/usr/local/include
LIBRARY_PATHS = -L.
LIBS = -lxerces-c

export ALL_C_SRC_FILE  = $(wildcard *.c)
export ALL_H_HEAD_FILE = $(wildcard *.h)
export ALL_CPP_SRC_FILE = $(wildcard *.cpp)
export ALL_HPP_SRC_FILE = $(wildcard *.hpp)

.PHONY: all init clean
all: init $(OUTPUT_DIR)$(OUTPUT)

init:
	mkdir -p $(OUTPUT_DIR)

$(OUTPUT_DIR)%.o: %.c $(ALL_H_HEAD_FILE)
	$(CC) -c -o$@ $(CFLAGS) $(INCLUDE_PATHS) $<

$(OUTPUT_DIR)%.o: %.cpp $(ALL_HPP_HEAD_FILE)
	$(CPLUSPLUS) -c -o $@ $(CFLAGS) $(INCLUDE_PATHS) $<

$(OUTPUT_DIR)$(OUTPUT): $(ALL_CPP_SRC_FILE:%.cpp=$(OUTPUT_DIR)%.o) $(ALL_C_SRC_FILE:%.c=$(OUTPUT_DIR)%.o)
	$(CC) -o $@ $(CFLAGS) $(LIBRARY_PATHS) $(LIBS) $?
	ln -s $(OUTPUT_DIR)$(OUTPUT) $(OUTPUT)
clean:
	rm -rf $(OUTPUT_DIR)
	rm -rf $(OUTPUT)

edit:
	vim -n -u $(MY_IDE_RC) -c TlistToggle ./ 
ledit:
	vim -n -u $(MY_IDE_RC) -c "normal '0"  -c TlistToggle 

